<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Let 案例</title>
</head>

<body>
    <div cLass="container">
        <h2 cLass="page-header">点击切换颜色</h2>
        <div cLass="item">123456</div>
        <div cLass="item">123465</div>
        <div cLass="item">123456</div>
    </div>
    <script>
        // 获取元素
        let items = document.getElementsByClassName("item");

        // 遍历绑定事件
        for (var i = 0; i < items.length; i++) {
            items[i].onclick = function () {
                this.style.background = "pink";
            }
        }

    </script>
</body>

</html>